/**
 * @param {string[]} names
 * @return {string[]}
 */
 var getFolderNames = function(names) {
  let map = new Map()
  for(let i=0;i<names.length;i++){
    if(!map.has(names[i])){
      map.set(names[i],0)
    }else {
      let t = names[i]
      while(map.has(t)){
       t =names[i]+'('+map.get(names[i])+1+')'
       map.set(names[i],map.get(names[i])+1)
      }
      map.set(t,0)
    }
  }
  return [...map.keys()]
};

console.log('pes'.substring(0,'pes'.lastIndexOf(')')-2));